﻿using System;
using System.Diagnostics.Contracts;
using EuroManager.Domain.Simulator.Engine;
using EuroManager.Domain.Simulator.Helpers;

namespace EuroManager.Domain.Simulator.World
{
    [ContractClass(typeof(PitchContract))]
    public interface IPitch
    {
        float Height { get; }

        float Width { get; }

        Vector2D Center { get; }
        
        Vector2D GoalLocation(PitchSide side);
        
        Vector2D MapToMetricalLocation(PitchSide side, Vector2D location);
        
        Vector2D MapToMetricalLocation(PitchSide side, float x, float y);

        Vector2D MapToProportionalLocation(PitchSide side, Vector2D location);

        Vector2D MapToProportionalLocation(PitchSide side, float x, float y);
    }

    [ContractClassFor(typeof(IPitch))]
    public abstract class PitchContract : IPitch
    {
        public abstract float Height { get; }

        public abstract float Width { get; }

        public abstract Vector2D Center { get; }

        public abstract Vector2D GoalLocation(PitchSide side);

        public abstract Vector2D MapToMetricalLocation(PitchSide side, Vector2D location);

        public Vector2D MapToMetricalLocation(PitchSide side, float x, float y)
        {
            Contract.Requires(x.IsRational() && 0 <= x && x <= 1);
            Contract.Requires(y.IsRational() && 0 <= y && y <= 1);
            return Vector2D.Zero;
        }

        public abstract Vector2D MapToProportionalLocation(PitchSide side, Vector2D location);

        public Vector2D MapToProportionalLocation(PitchSide side, float x, float y)
        {
            Contract.Requires(x.IsRational());
            Contract.Requires(y.IsRational());
            return Vector2D.Zero;
        }
    }
}
